
/*
 * Copyright (c) 2010, okazoh_tk. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  - Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *  - Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *  - Neither the name of the copyright holder nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include "alkes/gfx/LineShape.h"

namespace alkes {

LineShape::LineShape(uint32_t num)
: Shape(num)
{
    lines_.initialize(num);
}

LineShape::~LineShape()
{
}

const LineShape::Line& LineShape::getLine(uint32_t index) const
{
    return lines_[index];
}

const Point2D LineShape::getPoint0(uint32_t index) const
{
    AL_PRE_COND(validate(index), Point2D::ZERO);

    return lines_[index].pt0;
}

const Point2D LineShape::getPoint1(uint32_t index) const
{
    AL_PRE_COND(validate(index), Point2D::ZERO);

    return lines_[index].pt1;
}

const Color LineShape::getColor(uint32_t index) const
{
    AL_PRE_COND(validate(index), Color::BLACK);

    return lines_[index].color;
}

uint8_t LineShape::getWidth(uint32_t index) const
{
    AL_PRE_COND(validate(index), 1);

    return lines_[index].width;
}

void LineShape::setLine(
    const Point2D& pt0, const Point2D& pt1,
    const Color& color,
    uint8_t width)
{
    setLine(0, pt0, pt1, color, width);
}

void LineShape::setPoints(const Point2D& pt0, const Point2D& pt1)
{
    setPoints(0, pt0, pt1);
}

void LineShape::setColor(const Color& color)
{
    setColor(0, color);
}

void LineShape::setWidth(uint8_t width)
{
    setWidth(0, width);
}

void LineShape::setLine(
    uint32_t index,
    const Point2D& pt0, const Point2D& pt1,
    const Color& color,
    uint8_t width)
{
    setPoints(index, pt0, pt1);
    setColor(index, color);
    setWidth(index, width);
}

void LineShape::setPoints(uint32_t index, const Point2D& pt0, const Point2D& pt1)
{
    AL_PRE_COND(validate(index), );

    if (lines_[index].pt0 != pt0)
    {
        lines_[index].pt0 = pt0;
        setDirty(true);
    }

    if (lines_[index].pt1 != pt1)
    {
        lines_[index].pt1 = pt1;
        setDirty(true);
    }
}

void LineShape::setColor(uint32_t index, const Color& color)
{
    AL_PRE_COND(validate(index), );

    if (lines_[index].color != color)
    {
        lines_[index].color = color;
        setDirty(true);
    }
}

void LineShape::setWidth(uint32_t index, uint8_t width)
{
    AL_PRE_COND(validate(index), );

    if (lines_[index].width != width)
    {
        lines_[index].width = width;
        setDirty(true);
    }
}

}
